package com.one.apartmentsystem.common.config;

import com.alipay.api.AlipayConfig;
import com.alipay.api.domain.AlipayContract;
import com.one.apartmentsystem.common.properties.AliPayProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.alipay.api.AlipayConstants.*;

@Configuration
@EnableConfigurationProperties(AliPayProperties.class)
@Slf4j
public class AlibabaPayConfig {


    private final AliPayProperties aliPayProperties;

    public AlibabaPayConfig(AliPayProperties aliPayProperties) {
        this.aliPayProperties = aliPayProperties;
    }

    @Bean
    public AlipayConfig alipayConfig() {
        // 设置参数（全局只需设置一次）
        AlipayConfig alipayConfig = new AlipayConfig();
        //设置网关地址
        alipayConfig.setServerUrl(aliPayProperties.getServerUrl());
        //设置应用ID
        alipayConfig.setAppId(aliPayProperties.getAppId());
        //设置应用私钥
        alipayConfig.setPrivateKey(aliPayProperties.getAppPrivateKey());
        //设置支付宝公钥
        alipayConfig.setAlipayPublicKey(aliPayProperties.getAlipayPublicKey());
        log.info("=======支付宝SDK初始化成功=======");
        return alipayConfig;

    }
}
